//
// Created by lujun on 19-6-28.
//
// This contains SIN_COS , clarke, inv_clarke, park, inv_park and pid
// each one has it's own function.
// All function can be found in main function.
// If you don't want to use it, then comment it.
#include "../common.h"
#include "riscv_common_tables.h"
#include "riscv_const_structs.h"
#include "riscv_math.h"
#include <stdint.h>

#include "../HelperFunctions/math_helper.c"
#include "../HelperFunctions/ref_helper.c"

#include <stdio.h>
#define DELTAF32 (0.05f)
#define DELTAQ31 (63)
#define DELTAQ15 (1)
#define DELTAQ7 (1)

int test_flag_error = 0;

uint32_t fftSize = 1024;
uint32_t ifftFlag = 0;
uint32_t doBitReverse = 1;

static int DSP_cfft_radix4_f32(void)
{
    uint16_t i;

    float32_t cfft_testinput_f32_50hz_200Hz[512] = {
        2.00000000000000,      0.00000000000000,      1.79670533497009,
        -0.744219717332704,    1.26007351067010,      -1.26007351067010,
        0.581989529813420,     -1.40504701603470,     1.11022302462516e-16,
        -1.17557050458495,     -0.292893218813452,    -0.707106781186548,
        -0.221231742082474,    -0.221231742082474,    0.144973505364599,
        0.0600499921067857,    0.618033988749895,     1.11022302462516e-16,
        0.965451459415178,     -0.399903088302664,    1.00000000000000,
        -1.00000000000000,     0.652582529334717,     -1.57547359288761,
        -7.21644966006352e-16, -1.90211303259031,     -0.763007494114494,
        -1.84206304048352,     -1.39680224666742,     -1.39680224666742,
        -1.70710678118655,     -0.707106781186548,    -1.61803398874990,
        -4.44089209850063e-16, -1.20002351856331,     0.497066016555608,
        -0.642039521920207,    0.642039521920206,     -0.178671346220191,
        0.431350787252243,     0.00000000000000,      3.67394039744206e-16,
        -0.178671346220191,    -0.431350787252243,    -0.642039521920206,
        -0.642039521920206,    -1.20002351856331,     -0.497066016555607,
        -1.61803398874990,     1.22124532708767e-15,  -1.70710678118655,
        0.707106781186549,     -1.39680224666742,     1.39680224666742,
        -0.763007494114495,    1.84206304048352,      -7.77156117237610e-16,
        1.90211303259031,      0.652582529334716,     1.57547359288761,
        1.00000000000000,      1.00000000000000,      0.965451459415179,
        0.399903088302665,     0.618033988749895,     3.33066907387547e-16,
        0.144973505364597,     -0.0600499921067852,   -0.221231742082475,
        0.221231742082476,     -0.292893218813452,    0.707106781186550,
        -5.55111512312578e-16, 1.17557050458495,      0.581989529813419,
        1.40504701603470,      1.26007351067010,      1.26007351067010,
        1.79670533497008,      0.744219717332705,     2.00000000000000,
        1.22464679914735e-15,  1.79670533497008,      -0.744219717332707,
        1.26007351067010,      -1.26007351067010,     0.581989529813422,
        -1.40504701603470,     7.77156117237610e-16,  -1.17557050458495,
        -0.292893218813452,    -0.707106781186549,    -0.221231742082475,
        -0.221231742082475,    0.144973505364599,     0.0600499921067854,
        0.618033988749897,     -8.88178419700125e-16, 0.965451459415179,
        -0.399903088302667,    0.999999999999999,     -1.00000000000000,
        0.652582529334721,     -1.57547359288761,     1.49880108324396e-15,
        -1.90211303259031,     -0.763007494114497,    -1.84206304048352,
        -1.39680224666742,     -1.39680224666742,     -1.70710678118655,
        -0.707106781186545,    -1.61803398874990,     -1.33226762955019e-15,
        -1.20002351856331,     0.497066016555608,     -0.642039521920207,
        0.642039521920206,     -0.178671346220193,    0.431350787252245,
        0.00000000000000,      1.10218211923262e-15,  -0.178671346220191,
        -0.431350787252243,    -0.642039521920205,    -0.642039521920206,
        -1.20002351856332,     -0.497066016555606,    -1.61803398874989,
        -1.55431223447522e-15, -1.70710678118655,     0.707106781186550,
        -1.39680224666742,     1.39680224666743,      -0.763007494114492,
        1.84206304048352,      6.49480469405717e-15,  1.90211303259031,
        0.652582529334718,     1.57547359288761,      1.00000000000000,
        0.999999999999995,     0.965451459415180,     0.399903088302669,
        0.618033988749896,     7.77156117237610e-16,  0.144973505364603,
        -0.0600499921067867,   -0.221231742082474,    0.221231742082473,
        -0.292893218813452,    0.707106781186549,     -1.44328993201270e-15,
        1.17557050458495,      0.581989529813422,     1.40504701603470,
        1.26007351067010,      1.26007351067010,      1.79670533497009,
        0.744219717332702,     2.00000000000000,      2.44929359829471e-15,
        1.79670533497008,      -0.744219717332706,    1.26007351067010,
        -1.26007351067010,     0.581989529813419,     -1.40504701603470,
        -3.77475828372553e-15, -1.17557050458494,     -0.292893218813453,
        -0.707106781186546,    -0.221231742082475,    -0.221231742082476,
        0.144973505364595,     0.0600499921067846,    0.618033988749893,
        7.77156117237610e-16,  0.965451459415176,     -0.399903088302660,
        1.00000000000000,      -0.999999999999998,    0.652582529334716,
        -1.57547359288761,     2.66453525910038e-15,  -1.90211303259031,
        -0.763007494114496,    -1.84206304048352,     -1.39680224666742,
        -1.39680224666742,     -1.70710678118655,     -0.707106781186546,
        -1.61803398874989,     4.88498130835069e-15,  -1.20002351856331,
        0.497066016555607,     -0.642039521920202,    0.642039521920206,
        -0.178671346220190,    0.431350787252242,     0.00000000000000,
        -3.49210031947972e-15, -0.178671346220191,    -0.431350787252243,
        -0.642039521920198,    -0.642039521920206,    -1.20002351856331,
        -0.497066016555610,    -1.61803398874989,     -2.55351295663786e-15,
        -1.70710678118655,     0.707106781186549,     -1.39680224666742,
        1.39680224666742,      -0.763007494114502,    1.84206304048352,
        -3.16413562018170e-15, 1.90211303259031,      0.652582529334717,
        1.57547359288761,      1.00000000000000,      0.999999999999996,
        0.965451459415176,     0.399903088302658,     0.618033988749897,
        9.99200722162641e-16,  0.144973505364599,     -0.0600499921067855,
        -0.221231742082476,    0.221231742082477,     -0.292893218813451,
        0.707106781186554,     -2.10942374678780e-15, 1.17557050458494,
        0.581989529813421,     1.40504701603470,      1.26007351067009,
        1.26007351067011,      1.79670533497008,      0.744219717332711,
        2.00000000000000,      3.67394039744206e-15,  1.79670533497008,
        -0.744219717332705,    1.26007351067010,      -1.26007351067010,
        0.581989529813427,     -1.40504701603470,     2.22044604925031e-15,
        -1.17557050458495,     -0.292893218813453,    -0.707106781186547,
        -0.221231742082473,    -0.221231742082472,    0.144973505364605,
        0.0600499921067872,    0.618033988749893,     1.22124532708767e-15,
        0.965451459415178,     -0.399903088302665,    0.999999999999999,
        -1.00000000000000,     0.652582529334710,     -1.57547359288762,
        -1.31006316905768e-14, -1.90211303259031,     -0.763007494114495,
        -1.84206304048352,     -1.39680224666742,     -1.39680224666742,
        -1.70710678118655,     -0.707106781186539,    -1.61803398874989,
        1.09912079437891e-14,  -1.20002351856332,     0.497066016555607,
        -0.642039521920203,    0.642039521920206,     -0.178671346220186,
        0.431350787252238,     0.00000000000000,      -8.08638275819206e-15,
        -0.178671346220183,    -0.431350787252234,    -0.642039521920197,
        -0.642039521920205,    -1.20002351856331,     -0.497066016555611,
        -1.61803398874989,     -3.55271367880050e-15, -1.70710678118655,
        0.707106781186548,     -1.39680224666743,     1.39680224666741,
        -0.763007494114503,    1.84206304048352,      -4.32986979603811e-15,
        1.90211303259031,      0.652582529334717,     1.57547359288761,
        1.00000000000000,      0.999999999999997,     0.965451459415181,
        0.399903088302671,     0.618033988749898,     1.44328993201270e-15,
        0.144973505364600,     -0.0600499921067857,   -0.221231742082476,
        0.221231742082476,     -0.292893218813451,    0.707106781186553,
        -2.77555756156289e-15, 1.17557050458494,      0.581989529813420,
        1.40504701603470,      1.26007351067010,      1.26007351067010,
        1.79670533497009,      0.744219717332697,     2.00000000000000,
        4.89858719658941e-15,  1.79670533497009,      -0.744219717332704,
        1.26007351067010,      -1.26007351067010,     0.581989529813413,
        -1.40504701603470,     -7.54951656745106e-15, -1.17557050458494,
        -0.292893218813452,    -0.707106781186548,    -0.221231742082473,
        -0.221231742082472,    0.144973505364604,     0.0600499921067871,
        0.618033988749902,     -3.88578058618805e-15, 0.965451459415183,
        -0.399903088302676,    0.999999999999999,     -1.00000000000000,
        0.652582529334711,     -1.57547359288762,     5.05151476204446e-15,
        -1.90211303259031,     -0.763007494114493,    -1.84206304048352,
        -1.39680224666741,     -1.39680224666743,     -1.70710678118655,
        -0.707106781186557,    -1.61803398874990,     -4.44089209850063e-15,
        -1.20002351856332,     0.497066016555606,     -0.642039521920216,
        0.642039521920207,     -0.178671346220195,    0.431350787252247,
        0.00000000000000,      3.30654635769785e-15,  -0.178671346220190,
        -0.431350787252242,    -0.642039521920209,    -0.642039521920206,
        -1.20002351856331,     -0.497066016555611,    -1.61803398874989,
        -4.55191440096314e-15, -1.70710678118655,     0.707106781186546,
        -1.39680224666742,     1.39680224666742,      -0.763007494114487,
        1.84206304048352,      -5.44009282066327e-15, 1.90211303259031,
        0.652582529334716,     1.57547359288761,      1.00000000000000,
        0.999999999999998,     0.965451459415176,     0.399903088302660,
        0.618033988749888,     -3.66373598126302e-15, 0.144973505364600,
        -0.0600499921067860,   -0.221231742082475,    0.221231742082476,
        -0.292893218813451,    0.707106781186552,     6.88338275267597e-15,
        1.17557050458495,      0.581989529813434,     1.40504701603470,
        1.26007351067010,      1.26007351067010,      1.79670533497009,
        0.744219717332698,     2.00000000000000,      -1.16403343982657e-14,
        1.79670533497008,      -0.744219717332718,    1.26007351067010,
        -1.26007351067010,     0.581989529813414,     -1.40504701603470,
        1.40998324127395e-14,  -1.17557050458496,     -0.292893218813450,
        -0.707106781186561,    -0.221231742082479,    -0.221231742082482,
        0.144973505364593,     0.0600499921067840,    0.618033988749891,
        1.99840144432528e-15,  0.965451459415178,     -0.399903088302663,
        1.00000000000000,      -1.00000000000000,     0.652582529334712,
        -1.57547359288762,     -1.07136521876328e-14, -1.90211303259031,
        -0.763007494114476,    -1.84206304048353,     -1.39680224666741,
        -1.39680224666743,     -1.70710678118655,     -0.707106781186558,
        -1.61803398874990,     -5.44009282066327e-15, -1.20002351856332,
        0.497066016555606,     -0.642039521920205,    0.642039521920206,
        -0.178671346220187,    0.431350787252239,     0.00000000000000,
        -6.61680659921524e-15, -0.178671346220197,    -0.431350787252249,
        -0.642039521920220,    -0.642039521920207,    -1.20002351856331,
        -0.497066016555612,    -1.61803398874989,     -5.55111512312578e-15,
        -1.70710678118655,     0.707106781186545,     -1.39680224666742,
        1.39680224666742,      -0.763007494114488,    1.84206304048352,
        1.02140518265514e-14,  1.90211303259031,      0.652582529334727,
        1.57547359288760,      1.00000000000000,      0.999999999999984,
        0.965451459415172,     0.399903088302648,     0.618033988749899,
        2.10942374678780e-15,  0.144973505364601,     -0.0600499921067861,
        -0.221231742082475,    0.221231742082475,     -0.292893218813452,
        0.707106781186552,     -1.47659662275146e-14, 1.17557050458493,
        0.581989529813403,     1.40504701603470,      1.26007351067009,
        1.26007351067011,      1.79670533497008,      0.744219717332714,
        2.00000000000000,      7.34788079488412e-15,  1.79670533497009,
        -0.744219717332702,    1.26007351067010,      -1.26007351067010,
        0.581989529813416,     -1.40504701603470,     -5.99520433297585e-15,
        -1.17557050458494,     -0.292893218813455,    -0.707106781186538,
        -0.221231742082479,    -0.221231742082483,    0.144973505364592,
        0.0600499921067839,    0.618033988749891,     2.33146835171283e-15,
        0.965451459415177,     -0.399903088302663,    1.00000000000000,
        -1.00000000000000,     0.652582529334713,     -1.57547359288761,
        -9.54791801177635e-15, -1.90211303259031,     -0.763007494114508,
        -1.84206304048352,     -1.39680224666743,     -1.39680224666741,
        -1.70710678118655,     -0.707106781186559};
    float32_t cfft_testinput_f32_50hz_200Hz_ref[512] = {
        2.00000000000000,      0.00000000000000,      1.79670533497009,
        -0.744219717332704,    1.26007351067010,      -1.26007351067010,
        0.581989529813420,     -1.40504701603470,     1.11022302462516e-16,
        -1.17557050458495,     -0.292893218813452,    -0.707106781186548,
        -0.221231742082474,    -0.221231742082474,    0.144973505364599,
        0.0600499921067857,    0.618033988749895,     1.11022302462516e-16,
        0.965451459415178,     -0.399903088302664,    1.00000000000000,
        -1.00000000000000,     0.652582529334717,     -1.57547359288761,
        -7.21644966006352e-16, -1.90211303259031,     -0.763007494114494,
        -1.84206304048352,     -1.39680224666742,     -1.39680224666742,
        -1.70710678118655,     -0.707106781186548,    -1.61803398874990,
        -4.44089209850063e-16, -1.20002351856331,     0.497066016555608,
        -0.642039521920207,    0.642039521920206,     -0.178671346220191,
        0.431350787252243,     0.00000000000000,      3.67394039744206e-16,
        -0.178671346220191,    -0.431350787252243,    -0.642039521920206,
        -0.642039521920206,    -1.20002351856331,     -0.497066016555607,
        -1.61803398874990,     1.22124532708767e-15,  -1.70710678118655,
        0.707106781186549,     -1.39680224666742,     1.39680224666742,
        -0.763007494114495,    1.84206304048352,      -7.77156117237610e-16,
        1.90211303259031,      0.652582529334716,     1.57547359288761,
        1.00000000000000,      1.00000000000000,      0.965451459415179,
        0.399903088302665,     0.618033988749895,     3.33066907387547e-16,
        0.144973505364597,     -0.0600499921067852,   -0.221231742082475,
        0.221231742082476,     -0.292893218813452,    0.707106781186550,
        -5.55111512312578e-16, 1.17557050458495,      0.581989529813419,
        1.40504701603470,      1.26007351067010,      1.26007351067010,
        1.79670533497008,      0.744219717332705,     2.00000000000000,
        1.22464679914735e-15,  1.79670533497008,      -0.744219717332707,
        1.26007351067010,      -1.26007351067010,     0.581989529813422,
        -1.40504701603470,     7.77156117237610e-16,  -1.17557050458495,
        -0.292893218813452,    -0.707106781186549,    -0.221231742082475,
        -0.221231742082475,    0.144973505364599,     0.0600499921067854,
        0.618033988749897,     -8.88178419700125e-16, 0.965451459415179,
        -0.399903088302667,    0.999999999999999,     -1.00000000000000,
        0.652582529334721,     -1.57547359288761,     1.49880108324396e-15,
        -1.90211303259031,     -0.763007494114497,    -1.84206304048352,
        -1.39680224666742,     -1.39680224666742,     -1.70710678118655,
        -0.707106781186545,    -1.61803398874990,     -1.33226762955019e-15,
        -1.20002351856331,     0.497066016555608,     -0.642039521920207,
        0.642039521920206,     -0.178671346220193,    0.431350787252245,
        0.00000000000000,      1.10218211923262e-15,  -0.178671346220191,
        -0.431350787252243,    -0.642039521920205,    -0.642039521920206,
        -1.20002351856332,     -0.497066016555606,    -1.61803398874989,
        -1.55431223447522e-15, -1.70710678118655,     0.707106781186550,
        -1.39680224666742,     1.39680224666743,      -0.763007494114492,
        1.84206304048352,      6.49480469405717e-15,  1.90211303259031,
        0.652582529334718,     1.57547359288761,      1.00000000000000,
        0.999999999999995,     0.965451459415180,     0.399903088302669,
        0.618033988749896,     7.77156117237610e-16,  0.144973505364603,
        -0.0600499921067867,   -0.221231742082474,    0.221231742082473,
        -0.292893218813452,    0.707106781186549,     -1.44328993201270e-15,
        1.17557050458495,      0.581989529813422,     1.40504701603470,
        1.26007351067010,      1.26007351067010,      1.79670533497009,
        0.744219717332702,     2.00000000000000,      2.44929359829471e-15,
        1.79670533497008,      -0.744219717332706,    1.26007351067010,
        -1.26007351067010,     0.581989529813419,     -1.40504701603470,
        -3.77475828372553e-15, -1.17557050458494,     -0.292893218813453,
        -0.707106781186546,    -0.221231742082475,    -0.221231742082476,
        0.144973505364595,     0.0600499921067846,    0.618033988749893,
        7.77156117237610e-16,  0.965451459415176,     -0.399903088302660,
        1.00000000000000,      -0.999999999999998,    0.652582529334716,
        -1.57547359288761,     2.66453525910038e-15,  -1.90211303259031,
        -0.763007494114496,    -1.84206304048352,     -1.39680224666742,
        -1.39680224666742,     -1.70710678118655,     -0.707106781186546,
        -1.61803398874989,     4.88498130835069e-15,  -1.20002351856331,
        0.497066016555607,     -0.642039521920202,    0.642039521920206,
        -0.178671346220190,    0.431350787252242,     0.00000000000000,
        -3.49210031947972e-15, -0.178671346220191,    -0.431350787252243,
        -0.642039521920198,    -0.642039521920206,    -1.20002351856331,
        -0.497066016555610,    -1.61803398874989,     -2.55351295663786e-15,
        -1.70710678118655,     0.707106781186549,     -1.39680224666742,
        1.39680224666742,      -0.763007494114502,    1.84206304048352,
        -3.16413562018170e-15, 1.90211303259031,      0.652582529334717,
        1.57547359288761,      1.00000000000000,      0.999999999999996,
        0.965451459415176,     0.399903088302658,     0.618033988749897,
        9.99200722162641e-16,  0.144973505364599,     -0.0600499921067855,
        -0.221231742082476,    0.221231742082477,     -0.292893218813451,
        0.707106781186554,     -2.10942374678780e-15, 1.17557050458494,
        0.581989529813421,     1.40504701603470,      1.26007351067009,
        1.26007351067011,      1.79670533497008,      0.744219717332711,
        2.00000000000000,      3.67394039744206e-15,  1.79670533497008,
        -0.744219717332705,    1.26007351067010,      -1.26007351067010,
        0.581989529813427,     -1.40504701603470,     2.22044604925031e-15,
        -1.17557050458495,     -0.292893218813453,    -0.707106781186547,
        -0.221231742082473,    -0.221231742082472,    0.144973505364605,
        0.0600499921067872,    0.618033988749893,     1.22124532708767e-15,
        0.965451459415178,     -0.399903088302665,    0.999999999999999,
        -1.00000000000000,     0.652582529334710,     -1.57547359288762,
        -1.31006316905768e-14, -1.90211303259031,     -0.763007494114495,
        -1.84206304048352,     -1.39680224666742,     -1.39680224666742,
        -1.70710678118655,     -0.707106781186539,    -1.61803398874989,
        1.09912079437891e-14,  -1.20002351856332,     0.497066016555607,
        -0.642039521920203,    0.642039521920206,     -0.178671346220186,
        0.431350787252238,     0.00000000000000,      -8.08638275819206e-15,
        -0.178671346220183,    -0.431350787252234,    -0.642039521920197,
        -0.642039521920205,    -1.20002351856331,     -0.497066016555611,
        -1.61803398874989,     -3.55271367880050e-15, -1.70710678118655,
        0.707106781186548,     -1.39680224666743,     1.39680224666741,
        -0.763007494114503,    1.84206304048352,      -4.32986979603811e-15,
        1.90211303259031,      0.652582529334717,     1.57547359288761,
        1.00000000000000,      0.999999999999997,     0.965451459415181,
        0.399903088302671,     0.618033988749898,     1.44328993201270e-15,
        0.144973505364600,     -0.0600499921067857,   -0.221231742082476,
        0.221231742082476,     -0.292893218813451,    0.707106781186553,
        -2.77555756156289e-15, 1.17557050458494,      0.581989529813420,
        1.40504701603470,      1.26007351067010,      1.26007351067010,
        1.79670533497009,      0.744219717332697,     2.00000000000000,
        4.89858719658941e-15,  1.79670533497009,      -0.744219717332704,
        1.26007351067010,      -1.26007351067010,     0.581989529813413,
        -1.40504701603470,     -7.54951656745106e-15, -1.17557050458494,
        -0.292893218813452,    -0.707106781186548,    -0.221231742082473,
        -0.221231742082472,    0.144973505364604,     0.0600499921067871,
        0.618033988749902,     -3.88578058618805e-15, 0.965451459415183,
        -0.399903088302676,    0.999999999999999,     -1.00000000000000,
        0.652582529334711,     -1.57547359288762,     5.05151476204446e-15,
        -1.90211303259031,     -0.763007494114493,    -1.84206304048352,
        -1.39680224666741,     -1.39680224666743,     -1.70710678118655,
        -0.707106781186557,    -1.61803398874990,     -4.44089209850063e-15,
        -1.20002351856332,     0.497066016555606,     -0.642039521920216,
        0.642039521920207,     -0.178671346220195,    0.431350787252247,
        0.00000000000000,      3.30654635769785e-15,  -0.178671346220190,
        -0.431350787252242,    -0.642039521920209,    -0.642039521920206,
        -1.20002351856331,     -0.497066016555611,    -1.61803398874989,
        -4.55191440096314e-15, -1.70710678118655,     0.707106781186546,
        -1.39680224666742,     1.39680224666742,      -0.763007494114487,
        1.84206304048352,      -5.44009282066327e-15, 1.90211303259031,
        0.652582529334716,     1.57547359288761,      1.00000000000000,
        0.999999999999998,     0.965451459415176,     0.399903088302660,
        0.618033988749888,     -3.66373598126302e-15, 0.144973505364600,
        -0.0600499921067860,   -0.221231742082475,    0.221231742082476,
        -0.292893218813451,    0.707106781186552,     6.88338275267597e-15,
        1.17557050458495,      0.581989529813434,     1.40504701603470,
        1.26007351067010,      1.26007351067010,      1.79670533497009,
        0.744219717332698,     2.00000000000000,      -1.16403343982657e-14,
        1.79670533497008,      -0.744219717332718,    1.26007351067010,
        -1.26007351067010,     0.581989529813414,     -1.40504701603470,
        1.40998324127395e-14,  -1.17557050458496,     -0.292893218813450,
        -0.707106781186561,    -0.221231742082479,    -0.221231742082482,
        0.144973505364593,     0.0600499921067840,    0.618033988749891,
        1.99840144432528e-15,  0.965451459415178,     -0.399903088302663,
        1.00000000000000,      -1.00000000000000,     0.652582529334712,
        -1.57547359288762,     -1.07136521876328e-14, -1.90211303259031,
        -0.763007494114476,    -1.84206304048353,     -1.39680224666741,
        -1.39680224666743,     -1.70710678118655,     -0.707106781186558,
        -1.61803398874990,     -5.44009282066327e-15, -1.20002351856332,
        0.497066016555606,     -0.642039521920205,    0.642039521920206,
        -0.178671346220187,    0.431350787252239,     0.00000000000000,
        -6.61680659921524e-15, -0.178671346220197,    -0.431350787252249,
        -0.642039521920220,    -0.642039521920207,    -1.20002351856331,
        -0.497066016555612,    -1.61803398874989,     -5.55111512312578e-15,
        -1.70710678118655,     0.707106781186545,     -1.39680224666742,
        1.39680224666742,      -0.763007494114488,    1.84206304048352,
        1.02140518265514e-14,  1.90211303259031,      0.652582529334727,
        1.57547359288760,      1.00000000000000,      0.999999999999984,
        0.965451459415172,     0.399903088302648,     0.618033988749899,
        2.10942374678780e-15,  0.144973505364601,     -0.0600499921067861,
        -0.221231742082475,    0.221231742082475,     -0.292893218813452,
        0.707106781186552,     -1.47659662275146e-14, 1.17557050458493,
        0.581989529813403,     1.40504701603470,      1.26007351067009,
        1.26007351067011,      1.79670533497008,      0.744219717332714,
        2.00000000000000,      7.34788079488412e-15,  1.79670533497009,
        -0.744219717332702,    1.26007351067010,      -1.26007351067010,
        0.581989529813416,     -1.40504701603470,     -5.99520433297585e-15,
        -1.17557050458494,     -0.292893218813455,    -0.707106781186538,
        -0.221231742082479,    -0.221231742082483,    0.144973505364592,
        0.0600499921067839,    0.618033988749891,     2.33146835171283e-15,
        0.965451459415177,     -0.399903088302663,    1.00000000000000,
        -1.00000000000000,     0.652582529334713,     -1.57547359288761,
        -9.54791801177635e-15, -1.90211303259031,     -0.763007494114508,
        -1.84206304048352,     -1.39680224666743,     -1.39680224666741,
        -1.70710678118655,     -0.707106781186559};
    fftSize = 256;

    riscv_cfft_radix4_instance_f32 S;
    uint8_t ifftFlag = 0, doBitReverse = 1;
    riscv_cfft_radix4_init_f32(&S, 256, ifftFlag, doBitReverse);
    BENCH_START(riscv_cfft_radix4_f32);
    riscv_cfft_radix4_f32(&S, cfft_testinput_f32_50hz_200Hz);
    BENCH_END(riscv_cfft_radix4_f32);
    ref_cfft_radix4_f32(&S, cfft_testinput_f32_50hz_200Hz_ref);
    float32_t resault, resault_ref;
    uint32_t index, index_ref;
    riscv_max_f32(cfft_testinput_f32_50hz_200Hz, 256, &resault, &index);
    riscv_max_f32(cfft_testinput_f32_50hz_200Hz_ref, 256, &resault_ref,
                &index_ref);
    if (index != index_ref) {
        BENCH_ERROR(riscv_cfft_radix4_f32);
        printf("expect: %d, actual: %d\n", index_ref, index);
        test_flag_error = 1;
    }
    BENCH_STATUS(riscv_cfft_radix4_f32);
}

static int DSP_cfft_radix4_q15(void)
{
    uint16_t i;
    q15_t cfft_testinput_q15_50hz_200Hz[512] = {
        32767,  0,      32767,  -24386, 32767,  -32768, 19070,  -32768, 0,
        -32768, -9597,  -23170, -7249,  -7249,  4750,   1967,   20251,  0,
        31635,  -13104, 32767,  -32768, 21383,  -32768, 0,      -32768, -25002,
        -32768, -32768, -32768, -32768, -23170, -32768, 0,      -32768, 16287,
        -21038, 21038,  -5854,  14134,  0,      0,      -5854,  -14134, -21038,
        -21038, -32768, -16287, -32768, 0,      -32768, 23170,  -32768, 32767,
        -25002, 32767,  0,      32767,  21383,  32767,  32767,  32767,  31635,
        13104,  20251,  0,      4750,   -1967,  -7249,  7249,   -9597,  23170,
        0,      32767,  19070,  32767,  32767,  32767,  32767,  24386,  32767,
        0,      32767,  -24386, 32767,  -32768, 19070,  -32768, 0,      -32768,
        -9597,  -23170, -7249,  -7249,  4750,   1967,   20251,  0,      31635,
        -13104, 32767,  -32768, 21383,  -32768, 0,      -32768, -25002, -32768,
        -32768, -32768, -32768, -23170, -32768, 0,      -32768, 16287,  -21038,
        21038,  -5854,  14134,  0,      0,      -5854,  -14134, -21038, -21038,
        -32768, -16287, -32768, 0,      -32768, 23170,  -32768, 32767,  -25002,
        32767,  0,      32767,  21383,  32767,  32767,  32767,  31635,  13104,
        20251,  0,      4750,   -1967,  -7249,  7249,   -9597,  23170,  0,
        32767,  19070,  32767,  32767,  32767,  32767,  24386,  32767,  0,
        32767,  -24386, 32767,  -32768, 19070,  -32768, 0,      -32768, -9597,
        -23170, -7249,  -7249,  4750,   1967,   20251,  0,      31635,  -13104,
        32767,  -32768, 21383,  -32768, 0,      -32768, -25002, -32768, -32768,
        -32768, -32768, -23170, -32768, 0,      -32768, 16287,  -21038, 21038,
        -5854,  14134,  0,      0,      -5854,  -14134, -21038, -21038, -32768,
        -16287, -32768, 0,      -32768, 23170,  -32768, 32767,  -25002, 32767,
        0,      32767,  21383,  32767,  32767,  32767,  31635,  13104,  20251,
        0,      4750,   -1967,  -7249,  7249,   -9597,  23170,  0,      32767,
        19070,  32767,  32767,  32767,  32767,  24386,  32767,  0,      32767,
        -24386, 32767,  -32768, 19070,  -32768, 0,      -32768, -9597,  -23170,
        -7249,  -7249,  4750,   1967,   20251,  0,      31635,  -13104, 32767,
        -32768, 21383,  -32768, 0,      -32768, -25002, -32768, -32768, -32768,
        -32768, -23170, -32768, 0,      -32768, 16287,  -21038, 21038,  -5854,
        14134,  0,      0,      -5854,  -14134, -21038, -21038, -32768, -16287,
        -32768, 0,      -32768, 23170,  -32768, 32767,  -25002, 32767,  0,
        32767,  21383,  32767,  32767,  32767,  31635,  13104,  20251,  0,
        4750,   -1967,  -7249,  7249,   -9597,  23170,  0,      32767,  19070,
        32767,  32767,  32767,  32767,  24386,  32767,  0,      32767,  -24386,
        32767,  -32768, 19070,  -32768, 0,      -32768, -9597,  -23170, -7249,
        -7249,  4750,   1967,   20251,  0,      31635,  -13104, 32767,  -32768,
        21383,  -32768, 0,      -32768, -25002, -32768, -32768, -32768, -32768,
        -23170, -32768, 0,      -32768, 16287,  -21038, 21038,  -5854,  14134,
        0,      0,      -5854,  -14134, -21038, -21038, -32768, -16287, -32768,
        0,      -32768, 23170,  -32768, 32767,  -25002, 32767,  0,      32767,
        21383,  32767,  32767,  32767,  31635,  13104,  20251,  0,      4750,
        -1967,  -7249,  7249,   -9597,  23170,  0,      32767,  19070,  32767,
        32767,  32767,  32767,  24386,  32767,  0,      32767,  -24386, 32767,
        -32768, 19070,  -32768, 0,      -32768, -9597,  -23170, -7249,  -7249,
        4750,   1967,   20251,  0,      31635,  -13104, 32767,  -32768, 21383,
        -32768, 0,      -32768, -25002, -32768, -32768, -32768, -32768, -23170,
        -32768, 0,      -32768, 16287,  -21038, 21038,  -5854,  14134,  0,
        0,      -5854,  -14134, -21038, -21038, -32768, -16287, -32768, 0,
        -32768, 23170,  -32768, 32767,  -25002, 32767,  0,      32767,  21383,
        32767,  32767,  32767,  31635,  13104,  20251,  0,      4750,   -1967,
        -7249,  7249,   -9597,  23170,  0,      32767,  19070,  32767,  32767,
        32767,  32767,  24386,  32767,  0,      32767,  -24386, 32767,  -32768,
        19070,  -32768, 0,      -32768, -9597,  -23170, -7249,  -7249,  4750,
        1967,   20251,  0,      31635,  -13104, 32767,  -32768, 21383,  -32768,
        0,      -32768, -25002, -32768, -32768, -32768, -32768, -23170};
    q15_t cfft_testinput_q15_50hz_200Hz_ref[512] = {
        32767,  0,      32767,  -24386, 32767,  -32768, 19070,  -32768, 0,
        -32768, -9597,  -23170, -7249,  -7249,  4750,   1967,   20251,  0,
        31635,  -13104, 32767,  -32768, 21383,  -32768, 0,      -32768, -25002,
        -32768, -32768, -32768, -32768, -23170, -32768, 0,      -32768, 16287,
        -21038, 21038,  -5854,  14134,  0,      0,      -5854,  -14134, -21038,
        -21038, -32768, -16287, -32768, 0,      -32768, 23170,  -32768, 32767,
        -25002, 32767,  0,      32767,  21383,  32767,  32767,  32767,  31635,
        13104,  20251,  0,      4750,   -1967,  -7249,  7249,   -9597,  23170,
        0,      32767,  19070,  32767,  32767,  32767,  32767,  24386,  32767,
        0,      32767,  -24386, 32767,  -32768, 19070,  -32768, 0,      -32768,
        -9597,  -23170, -7249,  -7249,  4750,   1967,   20251,  0,      31635,
        -13104, 32767,  -32768, 21383,  -32768, 0,      -32768, -25002, -32768,
        -32768, -32768, -32768, -23170, -32768, 0,      -32768, 16287,  -21038,
        21038,  -5854,  14134,  0,      0,      -5854,  -14134, -21038, -21038,
        -32768, -16287, -32768, 0,      -32768, 23170,  -32768, 32767,  -25002,
        32767,  0,      32767,  21383,  32767,  32767,  32767,  31635,  13104,
        20251,  0,      4750,   -1967,  -7249,  7249,   -9597,  23170,  0,
        32767,  19070,  32767,  32767,  32767,  32767,  24386,  32767,  0,
        32767,  -24386, 32767,  -32768, 19070,  -32768, 0,      -32768, -9597,
        -23170, -7249,  -7249,  4750,   1967,   20251,  0,      31635,  -13104,
        32767,  -32768, 21383,  -32768, 0,      -32768, -25002, -32768, -32768,
        -32768, -32768, -23170, -32768, 0,      -32768, 16287,  -21038, 21038,
        -5854,  14134,  0,      0,      -5854,  -14134, -21038, -21038, -32768,
        -16287, -32768, 0,      -32768, 23170,  -32768, 32767,  -25002, 32767,
        0,      32767,  21383,  32767,  32767,  32767,  31635,  13104,  20251,
        0,      4750,   -1967,  -7249,  7249,   -9597,  23170,  0,      32767,
        19070,  32767,  32767,  32767,  32767,  24386,  32767,  0,      32767,
        -24386, 32767,  -32768, 19070,  -32768, 0,      -32768, -9597,  -23170,
        -7249,  -7249,  4750,   1967,   20251,  0,      31635,  -13104, 32767,
        -32768, 21383,  -32768, 0,      -32768, -25002, -32768, -32768, -32768,
        -32768, -23170, -32768, 0,      -32768, 16287,  -21038, 21038,  -5854,
        14134,  0,      0,      -5854,  -14134, -21038, -21038, -32768, -16287,
        -32768, 0,      -32768, 23170,  -32768, 32767,  -25002, 32767,  0,
        32767,  21383,  32767,  32767,  32767,  31635,  13104,  20251,  0,
        4750,   -1967,  -7249,  7249,   -9597,  23170,  0,      32767,  19070,
        32767,  32767,  32767,  32767,  24386,  32767,  0,      32767,  -24386,
        32767,  -32768, 19070,  -32768, 0,      -32768, -9597,  -23170, -7249,
        -7249,  4750,   1967,   20251,  0,      31635,  -13104, 32767,  -32768,
        21383,  -32768, 0,      -32768, -25002, -32768, -32768, -32768, -32768,
        -23170, -32768, 0,      -32768, 16287,  -21038, 21038,  -5854,  14134,
        0,      0,      -5854,  -14134, -21038, -21038, -32768, -16287, -32768,
        0,      -32768, 23170,  -32768, 32767,  -25002, 32767,  0,      32767,
        21383,  32767,  32767,  32767,  31635,  13104,  20251,  0,      4750,
        -1967,  -7249,  7249,   -9597,  23170,  0,      32767,  19070,  32767,
        32767,  32767,  32767,  24386,  32767,  0,      32767,  -24386, 32767,
        -32768, 19070,  -32768, 0,      -32768, -9597,  -23170, -7249,  -7249,
        4750,   1967,   20251,  0,      31635,  -13104, 32767,  -32768, 21383,
        -32768, 0,      -32768, -25002, -32768, -32768, -32768, -32768, -23170,
        -32768, 0,      -32768, 16287,  -21038, 21038,  -5854,  14134,  0,
        0,      -5854,  -14134, -21038, -21038, -32768, -16287, -32768, 0,
        -32768, 23170,  -32768, 32767,  -25002, 32767,  0,      32767,  21383,
        32767,  32767,  32767,  31635,  13104,  20251,  0,      4750,   -1967,
        -7249,  7249,   -9597,  23170,  0,      32767,  19070,  32767,  32767,
        32767,  32767,  24386,  32767,  0,      32767,  -24386, 32767,  -32768,
        19070,  -32768, 0,      -32768, -9597,  -23170, -7249,  -7249,  4750,
        1967,   20251,  0,      31635,  -13104, 32767,  -32768, 21383,  -32768,
        0,      -32768, -25002, -32768, -32768, -32768, -32768, -23170};
    fftSize = 256;
    riscv_cfft_radix4_instance_q15 S;
    uint8_t ifftFlag = 0, doBitReverse = 1;
    riscv_cfft_radix4_init_q15(&S, 256, ifftFlag, doBitReverse);
    BENCH_START(riscv_cfft_radix4_q15);
    riscv_cfft_radix4_q15(&S, cfft_testinput_q15_50hz_200Hz);
    BENCH_END(riscv_cfft_radix4_q15);
    ref_cfft_radix4_q15(&S, cfft_testinput_q15_50hz_200Hz_ref);
    q15_t resault, resault_ref;
    uint32_t index, index_ref = 117;
    riscv_shift_q15(cfft_testinput_q15_50hz_200Hz, 8,
                  cfft_testinput_q15_50hz_200Hz, fftSize);
    riscv_max_q15(cfft_testinput_q15_50hz_200Hz, 256, &resault, &index);
    riscv_shift_q15(cfft_testinput_q15_50hz_200Hz_ref, 8,
                  cfft_testinput_q15_50hz_200Hz_ref, fftSize);
    riscv_max_q15(cfft_testinput_q15_50hz_200Hz_ref, 256, &resault_ref,
                &index_ref);
    if (index != index_ref) {
        BENCH_ERROR(riscv_cfft_radix4_q15);
        printf("expect: %d, actual: %d\n", index_ref, index);
        test_flag_error = 1;
    }
    BENCH_STATUS(riscv_cfft_radix4_q15);
}
static int DSP_cfft_radix4_q31(void)
{
    uint16_t i;
    float32_t cfft_testinput_f32_50hz_200Hz[512] = {
        2.00000000000000,      0.00000000000000,      1.79670533497009,
        -0.744219717332704,    1.26007351067010,      -1.26007351067010,
        0.581989529813420,     -1.40504701603470,     1.11022302462516e-16,
        -1.17557050458495,     -0.292893218813452,    -0.707106781186548,
        -0.221231742082474,    -0.221231742082474,    0.144973505364599,
        0.0600499921067857,    0.618033988749895,     1.11022302462516e-16,
        0.965451459415178,     -0.399903088302664,    1.00000000000000,
        -1.00000000000000,     0.652582529334717,     -1.57547359288761,
        -7.21644966006352e-16, -1.90211303259031,     -0.763007494114494,
        -1.84206304048352,     -1.39680224666742,     -1.39680224666742,
        -1.70710678118655,     -0.707106781186548,    -1.61803398874990,
        -4.44089209850063e-16, -1.20002351856331,     0.497066016555608,
        -0.642039521920207,    0.642039521920206,     -0.178671346220191,
        0.431350787252243,     0.00000000000000,      3.67394039744206e-16,
        -0.178671346220191,    -0.431350787252243,    -0.642039521920206,
        -0.642039521920206,    -1.20002351856331,     -0.497066016555607,
        -1.61803398874990,     1.22124532708767e-15,  -1.70710678118655,
        0.707106781186549,     -1.39680224666742,     1.39680224666742,
        -0.763007494114495,    1.84206304048352,      -7.77156117237610e-16,
        1.90211303259031,      0.652582529334716,     1.57547359288761,
        1.00000000000000,      1.00000000000000,      0.965451459415179,
        0.399903088302665,     0.618033988749895,     3.33066907387547e-16,
        0.144973505364597,     -0.0600499921067852,   -0.221231742082475,
        0.221231742082476,     -0.292893218813452,    0.707106781186550,
        -5.55111512312578e-16, 1.17557050458495,      0.581989529813419,
        1.40504701603470,      1.26007351067010,      1.26007351067010,
        1.79670533497008,      0.744219717332705,     2.00000000000000,
        1.22464679914735e-15,  1.79670533497008,      -0.744219717332707,
        1.26007351067010,      -1.26007351067010,     0.581989529813422,
        -1.40504701603470,     7.77156117237610e-16,  -1.17557050458495,
        -0.292893218813452,    -0.707106781186549,    -0.221231742082475,
        -0.221231742082475,    0.144973505364599,     0.0600499921067854,
        0.618033988749897,     -8.88178419700125e-16, 0.965451459415179,
        -0.399903088302667,    0.999999999999999,     -1.00000000000000,
        0.652582529334721,     -1.57547359288761,     1.49880108324396e-15,
        -1.90211303259031,     -0.763007494114497,    -1.84206304048352,
        -1.39680224666742,     -1.39680224666742,     -1.70710678118655,
        -0.707106781186545,    -1.61803398874990,     -1.33226762955019e-15,
        -1.20002351856331,     0.497066016555608,     -0.642039521920207,
        0.642039521920206,     -0.178671346220193,    0.431350787252245,
        0.00000000000000,      1.10218211923262e-15,  -0.178671346220191,
        -0.431350787252243,    -0.642039521920205,    -0.642039521920206,
        -1.20002351856332,     -0.497066016555606,    -1.61803398874989,
        -1.55431223447522e-15, -1.70710678118655,     0.707106781186550,
        -1.39680224666742,     1.39680224666743,      -0.763007494114492,
        1.84206304048352,      6.49480469405717e-15,  1.90211303259031,
        0.652582529334718,     1.57547359288761,      1.00000000000000,
        0.999999999999995,     0.965451459415180,     0.399903088302669,
        0.618033988749896,     7.77156117237610e-16,  0.144973505364603,
        -0.0600499921067867,   -0.221231742082474,    0.221231742082473,
        -0.292893218813452,    0.707106781186549,     -1.44328993201270e-15,
        1.17557050458495,      0.581989529813422,     1.40504701603470,
        1.26007351067010,      1.26007351067010,      1.79670533497009,
        0.744219717332702,     2.00000000000000,      2.44929359829471e-15,
        1.79670533497008,      -0.744219717332706,    1.26007351067010,
        -1.26007351067010,     0.581989529813419,     -1.40504701603470,
        -3.77475828372553e-15, -1.17557050458494,     -0.292893218813453,
        -0.707106781186546,    -0.221231742082475,    -0.221231742082476,
        0.144973505364595,     0.0600499921067846,    0.618033988749893,
        7.77156117237610e-16,  0.965451459415176,     -0.399903088302660,
        1.00000000000000,      -0.999999999999998,    0.652582529334716,
        -1.57547359288761,     2.66453525910038e-15,  -1.90211303259031,
        -0.763007494114496,    -1.84206304048352,     -1.39680224666742,
        -1.39680224666742,     -1.70710678118655,     -0.707106781186546,
        -1.61803398874989,     4.88498130835069e-15,  -1.20002351856331,
        0.497066016555607,     -0.642039521920202,    0.642039521920206,
        -0.178671346220190,    0.431350787252242,     0.00000000000000,
        -3.49210031947972e-15, -0.178671346220191,    -0.431350787252243,
        -0.642039521920198,    -0.642039521920206,    -1.20002351856331,
        -0.497066016555610,    -1.61803398874989,     -2.55351295663786e-15,
        -1.70710678118655,     0.707106781186549,     -1.39680224666742,
        1.39680224666742,      -0.763007494114502,    1.84206304048352,
        -3.16413562018170e-15, 1.90211303259031,      0.652582529334717,
        1.57547359288761,      1.00000000000000,      0.999999999999996,
        0.965451459415176,     0.399903088302658,     0.618033988749897,
        9.99200722162641e-16,  0.144973505364599,     -0.0600499921067855,
        -0.221231742082476,    0.221231742082477,     -0.292893218813451,
        0.707106781186554,     -2.10942374678780e-15, 1.17557050458494,
        0.581989529813421,     1.40504701603470,      1.26007351067009,
        1.26007351067011,      1.79670533497008,      0.744219717332711,
        2.00000000000000,      3.67394039744206e-15,  1.79670533497008,
        -0.744219717332705,    1.26007351067010,      -1.26007351067010,
        0.581989529813427,     -1.40504701603470,     2.22044604925031e-15,
        -1.17557050458495,     -0.292893218813453,    -0.707106781186547,
        -0.221231742082473,    -0.221231742082472,    0.144973505364605,
        0.0600499921067872,    0.618033988749893,     1.22124532708767e-15,
        0.965451459415178,     -0.399903088302665,    0.999999999999999,
        -1.00000000000000,     0.652582529334710,     -1.57547359288762,
        -1.31006316905768e-14, -1.90211303259031,     -0.763007494114495,
        -1.84206304048352,     -1.39680224666742,     -1.39680224666742,
        -1.70710678118655,     -0.707106781186539,    -1.61803398874989,
        1.09912079437891e-14,  -1.20002351856332,     0.497066016555607,
        -0.642039521920203,    0.642039521920206,     -0.178671346220186,
        0.431350787252238,     0.00000000000000,      -8.08638275819206e-15,
        -0.178671346220183,    -0.431350787252234,    -0.642039521920197,
        -0.642039521920205,    -1.20002351856331,     -0.497066016555611,
        -1.61803398874989,     -3.55271367880050e-15, -1.70710678118655,
        0.707106781186548,     -1.39680224666743,     1.39680224666741,
        -0.763007494114503,    1.84206304048352,      -4.32986979603811e-15,
        1.90211303259031,      0.652582529334717,     1.57547359288761,
        1.00000000000000,      0.999999999999997,     0.965451459415181,
        0.399903088302671,     0.618033988749898,     1.44328993201270e-15,
        0.144973505364600,     -0.0600499921067857,   -0.221231742082476,
        0.221231742082476,     -0.292893218813451,    0.707106781186553,
        -2.77555756156289e-15, 1.17557050458494,      0.581989529813420,
        1.40504701603470,      1.26007351067010,      1.26007351067010,
        1.79670533497009,      0.744219717332697,     2.00000000000000,
        4.89858719658941e-15,  1.79670533497009,      -0.744219717332704,
        1.26007351067010,      -1.26007351067010,     0.581989529813413,
        -1.40504701603470,     -7.54951656745106e-15, -1.17557050458494,
        -0.292893218813452,    -0.707106781186548,    -0.221231742082473,
        -0.221231742082472,    0.144973505364604,     0.0600499921067871,
        0.618033988749902,     -3.88578058618805e-15, 0.965451459415183,
        -0.399903088302676,    0.999999999999999,     -1.00000000000000,
        0.652582529334711,     -1.57547359288762,     5.05151476204446e-15,
        -1.90211303259031,     -0.763007494114493,    -1.84206304048352,
        -1.39680224666741,     -1.39680224666743,     -1.70710678118655,
        -0.707106781186557,    -1.61803398874990,     -4.44089209850063e-15,
        -1.20002351856332,     0.497066016555606,     -0.642039521920216,
        0.642039521920207,     -0.178671346220195,    0.431350787252247,
        0.00000000000000,      3.30654635769785e-15,  -0.178671346220190,
        -0.431350787252242,    -0.642039521920209,    -0.642039521920206,
        -1.20002351856331,     -0.497066016555611,    -1.61803398874989,
        -4.55191440096314e-15, -1.70710678118655,     0.707106781186546,
        -1.39680224666742,     1.39680224666742,      -0.763007494114487,
        1.84206304048352,      -5.44009282066327e-15, 1.90211303259031,
        0.652582529334716,     1.57547359288761,      1.00000000000000,
        0.999999999999998,     0.965451459415176,     0.399903088302660,
        0.618033988749888,     -3.66373598126302e-15, 0.144973505364600,
        -0.0600499921067860,   -0.221231742082475,    0.221231742082476,
        -0.292893218813451,    0.707106781186552,     6.88338275267597e-15,
        1.17557050458495,      0.581989529813434,     1.40504701603470,
        1.26007351067010,      1.26007351067010,      1.79670533497009,
        0.744219717332698,     2.00000000000000,      -1.16403343982657e-14,
        1.79670533497008,      -0.744219717332718,    1.26007351067010,
        -1.26007351067010,     0.581989529813414,     -1.40504701603470,
        1.40998324127395e-14,  -1.17557050458496,     -0.292893218813450,
        -0.707106781186561,    -0.221231742082479,    -0.221231742082482,
        0.144973505364593,     0.0600499921067840,    0.618033988749891,
        1.99840144432528e-15,  0.965451459415178,     -0.399903088302663,
        1.00000000000000,      -1.00000000000000,     0.652582529334712,
        -1.57547359288762,     -1.07136521876328e-14, -1.90211303259031,
        -0.763007494114476,    -1.84206304048353,     -1.39680224666741,
        -1.39680224666743,     -1.70710678118655,     -0.707106781186558,
        -1.61803398874990,     -5.44009282066327e-15, -1.20002351856332,
        0.497066016555606,     -0.642039521920205,    0.642039521920206,
        -0.178671346220187,    0.431350787252239,     0.00000000000000,
        -6.61680659921524e-15, -0.178671346220197,    -0.431350787252249,
        -0.642039521920220,    -0.642039521920207,    -1.20002351856331,
        -0.497066016555612,    -1.61803398874989,     -5.55111512312578e-15,
        -1.70710678118655,     0.707106781186545,     -1.39680224666742,
        1.39680224666742,      -0.763007494114488,    1.84206304048352,
        1.02140518265514e-14,  1.90211303259031,      0.652582529334727,
        1.57547359288760,      1.00000000000000,      0.999999999999984,
        0.965451459415172,     0.399903088302648,     0.618033988749899,
        2.10942374678780e-15,  0.144973505364601,     -0.0600499921067861,
        -0.221231742082475,    0.221231742082475,     -0.292893218813452,
        0.707106781186552,     -1.47659662275146e-14, 1.17557050458493,
        0.581989529813403,     1.40504701603470,      1.26007351067009,
        1.26007351067011,      1.79670533497008,      0.744219717332714,
        2.00000000000000,      7.34788079488412e-15,  1.79670533497009,
        -0.744219717332702,    1.26007351067010,      -1.26007351067010,
        0.581989529813416,     -1.40504701603470,     -5.99520433297585e-15,
        -1.17557050458494,     -0.292893218813455,    -0.707106781186538,
        -0.221231742082479,    -0.221231742082483,    0.144973505364592,
        0.0600499921067839,    0.618033988749891,     2.33146835171283e-15,
        0.965451459415177,     -0.399903088302663,    1.00000000000000,
        -1.00000000000000,     0.652582529334713,     -1.57547359288761,
        -9.54791801177635e-15, -1.90211303259031,     -0.763007494114508,
        -1.84206304048352,     -1.39680224666743,     -1.39680224666741,
        -1.70710678118655,     -0.707106781186559};
    float32_t cfft_testinput_f32_50hz_200Hz_ref[512] = {
        2.00000000000000,      0.00000000000000,      1.79670533497009,
        -0.744219717332704,    1.26007351067010,      -1.26007351067010,
        0.581989529813420,     -1.40504701603470,     1.11022302462516e-16,
        -1.17557050458495,     -0.292893218813452,    -0.707106781186548,
        -0.221231742082474,    -0.221231742082474,    0.144973505364599,
        0.0600499921067857,    0.618033988749895,     1.11022302462516e-16,
        0.965451459415178,     -0.399903088302664,    1.00000000000000,
        -1.00000000000000,     0.652582529334717,     -1.57547359288761,
        -7.21644966006352e-16, -1.90211303259031,     -0.763007494114494,
        -1.84206304048352,     -1.39680224666742,     -1.39680224666742,
        -1.70710678118655,     -0.707106781186548,    -1.61803398874990,
        -4.44089209850063e-16, -1.20002351856331,     0.497066016555608,
        -0.642039521920207,    0.642039521920206,     -0.178671346220191,
        0.431350787252243,     0.00000000000000,      3.67394039744206e-16,
        -0.178671346220191,    -0.431350787252243,    -0.642039521920206,
        -0.642039521920206,    -1.20002351856331,     -0.497066016555607,
        -1.61803398874990,     1.22124532708767e-15,  -1.70710678118655,
        0.707106781186549,     -1.39680224666742,     1.39680224666742,
        -0.763007494114495,    1.84206304048352,      -7.77156117237610e-16,
        1.90211303259031,      0.652582529334716,     1.57547359288761,
        1.00000000000000,      1.00000000000000,      0.965451459415179,
        0.399903088302665,     0.618033988749895,     3.33066907387547e-16,
        0.144973505364597,     -0.0600499921067852,   -0.221231742082475,
        0.221231742082476,     -0.292893218813452,    0.707106781186550,
        -5.55111512312578e-16, 1.17557050458495,      0.581989529813419,
        1.40504701603470,      1.26007351067010,      1.26007351067010,
        1.79670533497008,      0.744219717332705,     2.00000000000000,
        1.22464679914735e-15,  1.79670533497008,      -0.744219717332707,
        1.26007351067010,      -1.26007351067010,     0.581989529813422,
        -1.40504701603470,     7.77156117237610e-16,  -1.17557050458495,
        -0.292893218813452,    -0.707106781186549,    -0.221231742082475,
        -0.221231742082475,    0.144973505364599,     0.0600499921067854,
        0.618033988749897,     -8.88178419700125e-16, 0.965451459415179,
        -0.399903088302667,    0.999999999999999,     -1.00000000000000,
        0.652582529334721,     -1.57547359288761,     1.49880108324396e-15,
        -1.90211303259031,     -0.763007494114497,    -1.84206304048352,
        -1.39680224666742,     -1.39680224666742,     -1.70710678118655,
        -0.707106781186545,    -1.61803398874990,     -1.33226762955019e-15,
        -1.20002351856331,     0.497066016555608,     -0.642039521920207,
        0.642039521920206,     -0.178671346220193,    0.431350787252245,
        0.00000000000000,      1.10218211923262e-15,  -0.178671346220191,
        -0.431350787252243,    -0.642039521920205,    -0.642039521920206,
        -1.20002351856332,     -0.497066016555606,    -1.61803398874989,
        -1.55431223447522e-15, -1.70710678118655,     0.707106781186550,
        -1.39680224666742,     1.39680224666743,      -0.763007494114492,
        1.84206304048352,      6.49480469405717e-15,  1.90211303259031,
        0.652582529334718,     1.57547359288761,      1.00000000000000,
        0.999999999999995,     0.965451459415180,     0.399903088302669,
        0.618033988749896,     7.77156117237610e-16,  0.144973505364603,
        -0.0600499921067867,   -0.221231742082474,    0.221231742082473,
        -0.292893218813452,    0.707106781186549,     -1.44328993201270e-15,
        1.17557050458495,      0.581989529813422,     1.40504701603470,
        1.26007351067010,      1.26007351067010,      1.79670533497009,
        0.744219717332702,     2.00000000000000,      2.44929359829471e-15,
        1.79670533497008,      -0.744219717332706,    1.26007351067010,
        -1.26007351067010,     0.581989529813419,     -1.40504701603470,
        -3.77475828372553e-15, -1.17557050458494,     -0.292893218813453,
        -0.707106781186546,    -0.221231742082475,    -0.221231742082476,
        0.144973505364595,     0.0600499921067846,    0.618033988749893,
        7.77156117237610e-16,  0.965451459415176,     -0.399903088302660,
        1.00000000000000,      -0.999999999999998,    0.652582529334716,
        -1.57547359288761,     2.66453525910038e-15,  -1.90211303259031,
        -0.763007494114496,    -1.84206304048352,     -1.39680224666742,
        -1.39680224666742,     -1.70710678118655,     -0.707106781186546,
        -1.61803398874989,     4.88498130835069e-15,  -1.20002351856331,
        0.497066016555607,     -0.642039521920202,    0.642039521920206,
        -0.178671346220190,    0.431350787252242,     0.00000000000000,
        -3.49210031947972e-15, -0.178671346220191,    -0.431350787252243,
        -0.642039521920198,    -0.642039521920206,    -1.20002351856331,
        -0.497066016555610,    -1.61803398874989,     -2.55351295663786e-15,
        -1.70710678118655,     0.707106781186549,     -1.39680224666742,
        1.39680224666742,      -0.763007494114502,    1.84206304048352,
        -3.16413562018170e-15, 1.90211303259031,      0.652582529334717,
        1.57547359288761,      1.00000000000000,      0.999999999999996,
        0.965451459415176,     0.399903088302658,     0.618033988749897,
        9.99200722162641e-16,  0.144973505364599,     -0.0600499921067855,
        -0.221231742082476,    0.221231742082477,     -0.292893218813451,
        0.707106781186554,     -2.10942374678780e-15, 1.17557050458494,
        0.581989529813421,     1.40504701603470,      1.26007351067009,
        1.26007351067011,      1.79670533497008,      0.744219717332711,
        2.00000000000000,      3.67394039744206e-15,  1.79670533497008,
        -0.744219717332705,    1.26007351067010,      -1.26007351067010,
        0.581989529813427,     -1.40504701603470,     2.22044604925031e-15,
        -1.17557050458495,     -0.292893218813453,    -0.707106781186547,
        -0.221231742082473,    -0.221231742082472,    0.144973505364605,
        0.0600499921067872,    0.618033988749893,     1.22124532708767e-15,
        0.965451459415178,     -0.399903088302665,    0.999999999999999,
        -1.00000000000000,     0.652582529334710,     -1.57547359288762,
        -1.31006316905768e-14, -1.90211303259031,     -0.763007494114495,
        -1.84206304048352,     -1.39680224666742,     -1.39680224666742,
        -1.70710678118655,     -0.707106781186539,    -1.61803398874989,
        1.09912079437891e-14,  -1.20002351856332,     0.497066016555607,
        -0.642039521920203,    0.642039521920206,     -0.178671346220186,
        0.431350787252238,     0.00000000000000,      -8.08638275819206e-15,
        -0.178671346220183,    -0.431350787252234,    -0.642039521920197,
        -0.642039521920205,    -1.20002351856331,     -0.497066016555611,
        -1.61803398874989,     -3.55271367880050e-15, -1.70710678118655,
        0.707106781186548,     -1.39680224666743,     1.39680224666741,
        -0.763007494114503,    1.84206304048352,      -4.32986979603811e-15,
        1.90211303259031,      0.652582529334717,     1.57547359288761,
        1.00000000000000,      0.999999999999997,     0.965451459415181,
        0.399903088302671,     0.618033988749898,     1.44328993201270e-15,
        0.144973505364600,     -0.0600499921067857,   -0.221231742082476,
        0.221231742082476,     -0.292893218813451,    0.707106781186553,
        -2.77555756156289e-15, 1.17557050458494,      0.581989529813420,
        1.40504701603470,      1.26007351067010,      1.26007351067010,
        1.79670533497009,      0.744219717332697,     2.00000000000000,
        4.89858719658941e-15,  1.79670533497009,      -0.744219717332704,
        1.26007351067010,      -1.26007351067010,     0.581989529813413,
        -1.40504701603470,     -7.54951656745106e-15, -1.17557050458494,
        -0.292893218813452,    -0.707106781186548,    -0.221231742082473,
        -0.221231742082472,    0.144973505364604,     0.0600499921067871,
        0.618033988749902,     -3.88578058618805e-15, 0.965451459415183,
        -0.399903088302676,    0.999999999999999,     -1.00000000000000,
        0.652582529334711,     -1.57547359288762,     5.05151476204446e-15,
        -1.90211303259031,     -0.763007494114493,    -1.84206304048352,
        -1.39680224666741,     -1.39680224666743,     -1.70710678118655,
        -0.707106781186557,    -1.61803398874990,     -4.44089209850063e-15,
        -1.20002351856332,     0.497066016555606,     -0.642039521920216,
        0.642039521920207,     -0.178671346220195,    0.431350787252247,
        0.00000000000000,      3.30654635769785e-15,  -0.178671346220190,
        -0.431350787252242,    -0.642039521920209,    -0.642039521920206,
        -1.20002351856331,     -0.497066016555611,    -1.61803398874989,
        -4.55191440096314e-15, -1.70710678118655,     0.707106781186546,
        -1.39680224666742,     1.39680224666742,      -0.763007494114487,
        1.84206304048352,      -5.44009282066327e-15, 1.90211303259031,
        0.652582529334716,     1.57547359288761,      1.00000000000000,
        0.999999999999998,     0.965451459415176,     0.399903088302660,
        0.618033988749888,     -3.66373598126302e-15, 0.144973505364600,
        -0.0600499921067860,   -0.221231742082475,    0.221231742082476,
        -0.292893218813451,    0.707106781186552,     6.88338275267597e-15,
        1.17557050458495,      0.581989529813434,     1.40504701603470,
        1.26007351067010,      1.26007351067010,      1.79670533497009,
        0.744219717332698,     2.00000000000000,      -1.16403343982657e-14,
        1.79670533497008,      -0.744219717332718,    1.26007351067010,
        -1.26007351067010,     0.581989529813414,     -1.40504701603470,
        1.40998324127395e-14,  -1.17557050458496,     -0.292893218813450,
        -0.707106781186561,    -0.221231742082479,    -0.221231742082482,
        0.144973505364593,     0.0600499921067840,    0.618033988749891,
        1.99840144432528e-15,  0.965451459415178,     -0.399903088302663,
        1.00000000000000,      -1.00000000000000,     0.652582529334712,
        -1.57547359288762,     -1.07136521876328e-14, -1.90211303259031,
        -0.763007494114476,    -1.84206304048353,     -1.39680224666741,
        -1.39680224666743,     -1.70710678118655,     -0.707106781186558,
        -1.61803398874990,     -5.44009282066327e-15, -1.20002351856332,
        0.497066016555606,     -0.642039521920205,    0.642039521920206,
        -0.178671346220187,    0.431350787252239,     0.00000000000000,
        -6.61680659921524e-15, -0.178671346220197,    -0.431350787252249,
        -0.642039521920220,    -0.642039521920207,    -1.20002351856331,
        -0.497066016555612,    -1.61803398874989,     -5.55111512312578e-15,
        -1.70710678118655,     0.707106781186545,     -1.39680224666742,
        1.39680224666742,      -0.763007494114488,    1.84206304048352,
        1.02140518265514e-14,  1.90211303259031,      0.652582529334727,
        1.57547359288760,      1.00000000000000,      0.999999999999984,
        0.965451459415172,     0.399903088302648,     0.618033988749899,
        2.10942374678780e-15,  0.144973505364601,     -0.0600499921067861,
        -0.221231742082475,    0.221231742082475,     -0.292893218813452,
        0.707106781186552,     -1.47659662275146e-14, 1.17557050458493,
        0.581989529813403,     1.40504701603470,      1.26007351067009,
        1.26007351067011,      1.79670533497008,      0.744219717332714,
        2.00000000000000,      7.34788079488412e-15,  1.79670533497009,
        -0.744219717332702,    1.26007351067010,      -1.26007351067010,
        0.581989529813416,     -1.40504701603470,     -5.99520433297585e-15,
        -1.17557050458494,     -0.292893218813455,    -0.707106781186538,
        -0.221231742082479,    -0.221231742082483,    0.144973505364592,
        0.0600499921067839,    0.618033988749891,     2.33146835171283e-15,
        0.965451459415177,     -0.399903088302663,    1.00000000000000,
        -1.00000000000000,     0.652582529334713,     -1.57547359288761,
        -9.54791801177635e-15, -1.90211303259031,     -0.763007494114508,
        -1.84206304048352,     -1.39680224666743,     -1.39680224666741,
        -1.70710678118655,     -0.707106781186559};
    q31_t cfft_testinput_q31_50hz_200Hz[512] = {0},
          cfft_testinput_q31_50hz_200Hz_ref[512] = {0};
    riscv_float_to_q31(cfft_testinput_f32_50hz_200Hz,
                     cfft_testinput_q31_50hz_200Hz, 512);
    riscv_float_to_q31(cfft_testinput_f32_50hz_200Hz_ref,
                     cfft_testinput_q31_50hz_200Hz_ref, 512);
    fftSize = 256;
    riscv_cfft_radix4_instance_q31 S;
    uint8_t ifftFlag = 0, doBitReverse = 1;
    riscv_cfft_radix4_init_q31(&S, 256, ifftFlag, doBitReverse);
    BENCH_START(riscv_cfft_radix4_q31);
    riscv_cfft_radix4_q31(&S, cfft_testinput_q31_50hz_200Hz);
    BENCH_END(riscv_cfft_radix4_q31);
    ref_cfft_radix4_q31(&S, cfft_testinput_q31_50hz_200Hz_ref);
    q31_t resault, resault_ref;
    uint32_t index, index_ref;
    riscv_max_q31(cfft_testinput_q31_50hz_200Hz, 256, &resault, &index);
    riscv_max_q31(cfft_testinput_q31_50hz_200Hz_ref, 256, &resault_ref,
                &index_ref);
    if (index != index_ref) {
        BENCH_ERROR(riscv_cfft_radix4_q31);
        printf("expect: %d, actual: %d\n", index_ref, index);
        test_flag_error = 1;
    }
    BENCH_STATUS(riscv_cfft_radix4_q31);
}

int main()
{
    BENCH_INIT;
    DSP_cfft_radix4_f32();
    DSP_cfft_radix4_q15();
    DSP_cfft_radix4_q31();
    BENCH_FINISH;
    if (test_flag_error) {
        printf("test error apprears, please recheck.\n");
        return 1;
    } else {
        printf("all test are passed. Well done!\n");
    }
    return 0;
}
